<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<title>测评任务添加</title>
		<link rel="shortcut icon" href="../../images/my/favicon.ico" />
		<link rel="bookmark" href="../../images/my/favicon.ico" />
		<link rel="stylesheet" href="../../statics/layui/css/layui.css" />
		<link rel="stylesheet" href="../../css/admin/common.css" />
		<!--<link rel="stylesheet" href="../../css/admin/update_my_base_info.css" />-->
	</head>

	<body style="background: #F6F6F6;">
		<div class="layui-fluid">
			<div class="layui-row">
				<div class="layui-col-md12">
					<div class="layui-card layui-anim layui-anim-upbit">
						<div class="layui-card-header">添加测评任务
							<span class="btn_right">
								<button type="button" id="back" title="返回" class="layui-btn layui-btn-normal layui-btn-xs" onclick="javascript:window.history.back(-1);"><i class="layui-icon">&#xe65c;</i>返回</button>
								<button type="button" id="refresh" title="刷新" class="layui-btn layui-btn-normal layui-btn-xs"><i class="layui-icon layui-icon-refresh"></i></button>
							</span>
						</div>
						<div class="layui-card-body">
							<form class="layui-form" action="">
								<div class="layui-form-item">
									<label class="layui-form-label">测评批次</label>
									<div class="layui-input-block">
										<input type="text" name="wtNumber" required lay-verify="required|wtNumber" autocomplete="off" placeholder="请输入测评批次编号(例：201809)" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label">开始日期</label>
										<div class="layui-input-inline">
											<input type="text" name="wtBegin" id="date" lay-verify="datetime" placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">结束日期</label>
										<div class="layui-input-inline">
											<input type="text" name="wtEnd" id="date1" lay-verify="datetime" placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" class="layui-input">
										</div>
									</div>
								</div>
								<div class="layui-form-item layui-form-text">
									<label class="layui-form-label">说明</label>
									<div class="layui-input-block">
										<textarea placeholder="请说明该次测评明细(500字符)" class="layui-textarea" name="wtDescribe"></textarea>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">状态</label>
									<div class="layui-input-block">
										<input type="checkbox" name="wtState" lay-skin="switch" lay-text="开启|关闭">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">&nbsp;</label>
									<button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo"></i><span>提交</span></button>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript" src="../../statics/layui/layui.js"></script>
		<script type="text/javascript" src="../../statics/lay/system/admin/public.js"></script>
		<script>
			layui.use(['layer', 'form', 'layedit', 'laydate'], function() {
				var layer = layui.layer,
					$ = layui.$,
					form = layui.form,
					layedit = layui.layedit,
					laydate = layui.laydate;
				//日期
				laydate.render({
					elem: '#date',
					type: 'datetime'
				});
				//日期
				laydate.render({
					elem: '#date1',
					type: 'datetime'
				});
				//表单监听提交
				form.on('submit(formDemo)', function(data) {
					var user_data = data.field;
					if(user_data.wtState == "on") {
						user_data.wtState = 1;
					}
					user_data = JSON.stringify(user_data)
					var begin = $('input[name=wtBegin]').val();
					var end = $('input[name=wtEnd]').val();
					strbegin = begin.replace(/-/g, '/'); // 将-替换成/，因为下面这个构造函数只支持/分隔的日期字符串
					strend = end.replace(/-/g, '/'); // 将-替换成/，因为下面这个构造函数只支持/分隔的日期字符串
					var date1 = new Date(strbegin); // 构造一个日期型数据，值为传入的字符串	
					var date2 = new Date(strend); // 构造一个日期型数据，值为传入的字符串
					if(date1.getTime() >= date2.getTime()) {
						layer.msg("结束时间必须大于开始时间")
					} else {
						inindate(user_data);
					}
					return false;
				});

				function inindate(data) {
					$.ajax({
						url: IP + '/api/teacher_eav/evaManager',
						type: 'POST',
						data: data,
						dataType: 'json',
						contentType: "application/json; charset=utf-8",
						success: function(result, status, xhr) {
							layer.closeAll('loading');
							if(result.code == 400) {
								layer.msg(result.data, {
									icon: 2,
									time: 1000
								});
							} else {
								layer.msg(result.message, {
									icon: 1,
									time: 1000
								}, function() {
									window.location.href = "task_list.html";
								});
							}
						}
					});
				}
				form.verify({
					wtNumber: function(value, item) { //value：表单的值、item：表单的DOM对象
						if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
							return '测评批次编号不能有特殊字符 例：201809';
						}
						if(!(/^[\S]{6}$/.test(value))) {
							return '测评批次编号必须6位，且不能出现空格 例：201809';
						}
						if(/(^\_)|(\__)|(\_+$)/.test(value)) {
							return '测评批次编号首尾不能出现下划线\'_\'';
						}
					}
				});
			});
		</script>
	</body>

</html>